﻿using System;
using System.Windows;
using MyAnimelistRecommender.Properties;
using MyAnimelistRecommender.View;

namespace MyAnimelistRecommender
{
    /// <summary>
    /// Interaktionslogik für "App.xaml"
    /// </summary>
    public partial class App : Application
    {
        private static RecommendationModel _Datamodel;

        public static RecommendationModel Model
        {
            get
            {
                if (_Datamodel == null)
                {
                    _Datamodel = new RecommendationModel();
                }

                return _Datamodel;
            }
            set
            {
                _Datamodel = value;
            }
        }

        private Random r = new Random();

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            MyAnimelistRecommender.Properties.Configuration.Default.InitializeDirtifying();
            View = new MainWindow();
            //Viewm = new MetroWindow();
            View.Show();
            //Viewm.Show();

            // <anime aid="1">
            //    <title type="short" xml:lang="en">CotS</title>
            //    <title type="official" xml:lang="pl">Crest of the Stars</title>
            //    <title type="official" xml:lang="en">Crest of the Stars</title>
            //    <title type="official" xml:lang="fr">Crest of the Stars</title>
            //    <title type="main" xml:lang="x-jat">Seikai no Monshou</title>
            //    <title type="short" xml:lang="x-jat">SnM</title>
            //    <title type="syn" xml:lang="zh-Hans">星界之纹章</title>
            //    <title type="official" xml:lang="ja">星界の紋章</title>
            //</anime>

            return;

            /*View.ShowInTaskbar = false;
            View.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            View.WindowState = WindowState.Minimized;

            var t = new Thread(() =>
               {
                   if (r.Next(10000000) % 2 == 0)
                   {
                       splash = new MyAnimelistRecommender.SplashScreen();
                       splash.StarteEndlichEvent += new EventHandler(splash_StarteEndlichEvent);
                       splash.Show();
                   }
                   else
                   {
                       splash2 = new Splash();
                       splash2.StarteEndlichEvent += new EventHandler(splash_StarteEndlichEvent);
                       splash2.Show();
                   }
                   System.Windows.Threading.Dispatcher.Run();
               });
            t.SetApartmentState(ApartmentState.STA);
            t.Start();*/
        }

        private MetroWindow Viewm = null;
        private MainWindow View = null;
        //SplashScreen splash = null;
        //Splash splash2 = null;

        private void splash_StarteEndlichEvent(object sender, EventArgs e)
        {
            View.Dispatcher.BeginInvoke((Action)delegate
            {
                Application.Current.MainWindow = View;

                Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

                View.ShowInTaskbar = true;
                View.WindowState = WindowState.Normal;
                View.Show();
            });
        }
    }
}